package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Materialtemplate;
import com.ruoyi.system.service.IMaterialtemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.uuid.UUID;

/**
 * 模板清单Controller
 * 
 * @author ruoyi
 * @date 2023-05-30
 */
@RestController
@RequestMapping("/materialtemplate/materialtemplate")
public class MaterialtemplateController extends BaseController
{
    @Autowired
    private IMaterialtemplateService materialtemplateService;

    /**
     * 查询模板清单列表
     */
    @PreAuthorize("@ss.hasPermi('materialtemplate:materialtemplate:list')")
    @GetMapping("/list")
    public TableDataInfo list(Materialtemplate materialtemplate)
    {
        startPage();
        List<Materialtemplate> list = materialtemplateService.selectMaterialtemplateList(materialtemplate);
        for (Materialtemplate materialtemplate1 : list) {
            System.out.println(materialtemplate1);
        }
        System.out.println("查询中。。。");
        if (list == null)
            System.out.println("null");
        else
            System.out.println("not null");
        return getDataTable(list);
    }

    /**
     * 导出模板清单列表
     */
    @PreAuthorize("@ss.hasPermi('materialtemplate:materialtemplate:export')")
    @Log(title = "模板清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Materialtemplate materialtemplate)
    {
        List<Materialtemplate> list = materialtemplateService.selectMaterialtemplateList(materialtemplate);
        ExcelUtil<Materialtemplate> util = new ExcelUtil<Materialtemplate>(Materialtemplate.class);
        util.exportExcel(response, list, "模板清单数据");
    }

    /**
     * 获取模板清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('materialtemplate:materialtemplate:query')")
    @GetMapping(value = "/{mSn}")
    public AjaxResult getInfo(@PathVariable("mSn") String mSn)
    {
        return success(materialtemplateService.selectMaterialtemplateByMSn(mSn));
    }

    /**
     * 新增模板清单
     */
    @PreAuthorize("@ss.hasPermi('materialtemplate:materialtemplate:add')")
    @Log(title = "模板清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Materialtemplate materialtemplate)
    {
        UUID uuid = UUID.randomUUID();
        String str = uuid.toString();
        String temp = str.replace("-","");
        materialtemplate.setmSn(temp);
        return toAjax(materialtemplateService.insertMaterialtemplate(materialtemplate));
    }

    /**
     * 修改模板清单
     */
    @PreAuthorize("@ss.hasPermi('materialtemplate:materialtemplate:edit')")
    @Log(title = "模板清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Materialtemplate materialtemplate)
    {
        return toAjax(materialtemplateService.updateMaterialtemplate(materialtemplate));
    }

    /**
     * 删除模板清单
     */
    @PreAuthorize("@ss.hasPermi('materialtemplate:materialtemplate:remove')")
    @Log(title = "模板清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mSns}")
    public AjaxResult remove(@PathVariable String[] mSns)
    {
        return toAjax(materialtemplateService.deleteMaterialtemplateByMSns(mSns));
    }
}
